package com.itheima.web;

import com.itheima.dto.SetmealDto;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import com.itheima.support.Result;
import com.itheima.utils.RedisUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @DubboReference
    private SetmealService setmealService;

    //查看所有套餐
    @GetMapping("/findAll")
    public Result<List<Setmeal>>findAll(){
        List<Setmeal> setmeal = RedisUtil.get("setmeal");
        if (setmeal==null){
            List<Setmeal> setmealList = setmealService.list();
            RedisUtil.set("setmeal",setmealList);
        }
        return Result.build(RedisUtil.get("setmeal"));
    }

    //套餐详细信息
    @GetMapping("/detail/{setmealId}")
    public Result<SetmealDto>detail(@PathVariable("setmealId")Long setmealId){

        return Result.build(setmealService.detail(setmealId));

    }
    @GetMapping("/info/{id}")
    public Result<Setmeal> info(@PathVariable("id") Long id){
        return Result.build(setmealService.getById(id));
    }


}
